<?php
				function ShowProfessors($id)
				{
					echo '<p class="minor_title">Διδάσκοντες: ';
					
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
					'SELECT Users.Name, Users.Surname
					 FROM Users, ProfessorsCourses
					 WHERE ProfessorsCourses.CourseId = ' . $id . ' AND 
					 ProfessorsCourses.ProfessorName = Users.Username');
					 
					 $first = true;
					 while($rs->next())
					 {
					 	list($name, $surname) = $rs->getCurrentValues();
					 	if($first == false)
					 		echo ', ';
					 	echo $name . ' ' . $surname;
					 	$first = false;
					 }
					
					echo '</p>';
				}
				
				function ShowWatchAnchor($id)
				{
					if(!isset($_SESSION['user']))
						return;
				
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
					'SELECT *
					 FROM UsersCourses
					 WHERE UsersCourses.UserName = \'' . $_SESSION['username'] . '\' 
					 AND UsersCourses.CourseId = ' . $id);
					 
					if($rs->next())
						echo '<a class="anchor" href="watch_course.php?action=remove&id=' . $id
						. '">διακοπή παρακολούθησης</a>';
					else
						echo '<a class="anchor" href="watch_course.php?action=add&id=' . $id
						. '">παρακολούθηση μαθήματος</a>';						
				}
				
				function ShowProfessorAnchor($id)
				{
					if(!isset($_SESSION['user']) || $_SESSION['position'] == 'Stud')
						return true;
				
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
					'SELECT *
					 FROM ProfessorsCourses
					 WHERE ProfessorsCourses.ProfessorName = \'' . $_SESSION['username'] . '\' 
					 AND ProfessorsCourses.CourseId = ' . $id);
					 
					if($rs->next())
					{
						echo '<a class="anchor" href="teach_course.php?action=remove&id=' . $id
						. '">διακοπή παρακολούθησης ως καθηγητής</a>';
						
						return false;
					}
					else
					{
						echo '<a class="anchor" href="teach_course.php?action=add&id=' . $id
						. '">παρακολούθηση μαθήματος ως καθηγητής</a>';
						echo  '&nbsp;&nbsp;&nbsp;&nbsp;';
						
						return true;
					}
				}
				
				function IsUserStudent($id)
				{
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
						'SELECT Name
						 FROM Courses, UsersCourses
						 WHERE UserName = \'' . $_SESSION['username'] . '\' AND CourseId = ' .
						 $id);
					
					if($rs->next())
					{
						return true;
					}
					
					return false;
				}

				function IsUserProf($id)
				{
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
						'SELECT *
						 FROM Courses, ProfessorsCourses
						 WHERE ProfessorName = \'' . $_SESSION['username'] . '\' AND CourseId = ' .
						 $id
					);
					
					if($rs->next())
					{
						return true;
					}
					
					return false;
				}

				function FindCourse($id, &$name)
				{
					if(!isset($id))
						return false;
				
					$db = new Database('Eclass');
					$rs = $db->executeQuery(
						'SELECT Name
						 FROM Courses
						 WHERE Id = ' . $id
					);
					
					if($rs->next())
					{
						list($name) = $rs->getCurrentValues();
						return true;
					}
					
					return false;
				}
?>
